<?php


namespace App\Extensions;

use Closure;
use Encore\Admin\Form;

class LayerForm extends Form
{

    /**
     * Create a new form instance.
     *
     * @param $model
     * @param \Closure $callback
     */
    public function __construct($model, Closure $callback = null)
    {
        parent::__construct($model, $callback);
        $this->setView('admin.layer-form');
        //$this->setAction(request()->getPathInfo());
    }

    public function setActionCurrent()
    {
        $this->setAction(url(request()->getPathInfo()));
    }

    public function setOriginalAction($id)
    {
        $this->setAction($this->resource() . '/' . $id);
    }

    //自定义返回
    protected function redirectAfterSaving($resourcesPath, $key)
    {
        return back()->with('success', '操作成功');
    }

    public function backErrors($provider, $key = 'default'): \Illuminate\Http\RedirectResponse
    {
        return back()->withInput()->withErrors($provider, $key);
    }

    public function backSuccess($msg = '操作成功'): \Illuminate\Http\RedirectResponse
    {
        return back()->with('success', $msg);
    }

    public function backAbort($message = 'Not Found', $code = 404): \Illuminate\Http\Response
    {
        return response()->view('errors.' . $code, compact('message', 'code'));
    }


}
